package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.duxiaoman.DuXiaoManFraudFactorData;
import com.ucredit.babel.common.model.duxiaoman.DuXiaoManFraudFactorRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;


/*
 * 度小满欺诈因子
 *
 * @author:szw
 * */

public class DuXiaoManFraudFactorParse extends ParseBase {
    private Text key = new Text();
    private Text val = new Text();

    /**
     * 度小满欺诈因子
     *
     * @param context
     * @param model
     * @param successful
     * @return boolean
     * @throws IOException
     * @throws InterruptedException
     * @author typole
     * @date 2020/12/01 5:08 下午
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        DuXiaoManFraudFactorRecord obj = (DuXiaoManFraudFactorRecord) model;
        DuXiaoManFraudFactorData data = obj.getData();

        // 创建字符串序列化对象
        StringBuilder sb = getBaseInfo(obj, successful);
        StringBuilder DxmSb = new StringBuilder(2000);

        DxmSb.append(data.getRetCode()).append(CRT001);
        DxmSb.append(data.getRetMsg() == null ? "" : data.getRetMsg()).append(CRT001);
        DxmSb.append(data.getResult().getScore() == null ? "" : data.getResult().getScore()).append(CRT001);

        key.set(getKey());
        val.set((sb.toString() + DxmSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_dxm_fraud_factor_inc";
    }

    @Override
    public String getType() {
        return RecordType.DUXIAOMAN_FRAUD_FACTOR_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "度小满欺诈因子";
    }
}
